# -*- coding: utf-8 -*-

from .filebuf import UrlFileBuf
from .png import Png
from .jpg import Jpg
from .gif import Gif
from .bmp import Bmp
from .webp import Webp

_IMG_CLASSES = (Jpg, Png, Gif, Bmp, Webp)
SUPPORT_FORMAT_NAMES = tuple([i.__FORMAT__ for i in _IMG_CLASSES])


def from_url(url):
    '''从 http url 获取一张图片的尺寸和大小的信息

    Args:
        url (TODO): TODO

    Returns: (ImgSize 对象, 图片类型名)

    '''
    fobj = UrlFileBuf(url, 512)
    # 遍历 _IMG_CLASSES 找到对应的文件类型
    for cls in _IMG_CLASSES:
        if cls.test(fobj):
            return cls.size(fobj), cls.__FORMAT__
    return None, None


__all__ = ('from_url', 'SUPPORT_FORMAT_NAMES')
